import 'package:daoyi_ui_admin_getx/generated/locales.g.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class CommonPickerUtil {
  static Future<int?> showPicker({
    required BuildContext context,
    List<String> options = const [],
    int value = 0,
    double height = 300,
  }) {
    FixedExtentScrollController controller =
        FixedExtentScrollController(initialItem: value);
    return showCupertinoModalPopup(
      context: context,
      builder: (BuildContext context) {
        return Container(
          color: Colors.grey,
          height: height,
          child: Column(
            children: [
              Container(
                height: 40,
                decoration: BoxDecoration(
                  color: Get.theme.primaryColor,
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    TextButton(
                      onPressed: () {
                        Navigator.of(context).pop(value);
                      },
                      child: Text(
                        LocaleKeys.buttons_cancel.tr,
                        style: TextStyle(
                          color: Get.theme.colorScheme.surface,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                    ),
                    TextButton(
                      onPressed: () {
                        Navigator.of(context).pop(controller.selectedItem);
                      },
                      child: Text(
                        LocaleKeys.buttons_confirm.tr,
                        style: TextStyle(
                          color: Get.theme.colorScheme.surface,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: CupertinoPicker(
                  scrollController: controller,
                  itemExtent: 32.0,
                  backgroundColor: Get.theme.scaffoldBackgroundColor,
                  onSelectedItemChanged: (value) {},
                  children: options
                      .map(
                        (item) => Text(item),
                      )
                      .toList(),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
